//
//  UIImageView+WebImage.swift
//  仿新浪微博
//
//  Created by 杨帆 on 16/7/6.
//  Copyright © 2016年 杨帆. All rights reserved.
//

import SDWebImage

extension UIImageView {

    func YF_setImage(urlString: String?, placeholderImage: UIImage?, isAvatar: Bool = false) {

        // 处理URL
       guard let urlString = urlString,
        
        url = URL(string: urlString) else {
        
            // 设置占位图像
            image = placeholderImage
            
            return
        }
        
        // 可选项只用在Swift OC可以用 也可以传 nil
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { [weak self] (image, _, _, _) in
            
            // 完成回调 判断是否是头像
            if isAvatar {
            
                self?.image = image?.cz_avatarImage(size: self?.bounds.size)
            }
        }
    }
}
